<!DOCTYPE HTML>
<html>
<head>
    <title>注册</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
	  	
  
    <!-------------jquery库-------------->
  	<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
	<!-------------Amazeui--------------->
    <script type="text/javascript" src="js/amazeui.js"></script>
    
    <link rel="stylesheet" type="text/css" href="css/amazeui.css">
    <!------------核心样式-------------->
    <link rel="stylesheet" type="text/css" href="css/user.css">  
	 <!-------------注册js-------------->
  	<script type="text/javascript">
		$(function() {
	$("input[name=passport]").blur(
			function() {
				var passport = $(this).val();
				if (!formObj.checkNull("passport", "手机号不能为空")) {
					setMsg("passport", "手机号不能为空");
				} else {

					$.ajax({
						url:"/user/checkUserphone",
						type:"post",
						data:{"passport":passport},
						dataType:"json",
						success:function(result){
							if (result.status!=200) {
								$("#passport_msg").html("手机号已存在");
							} else{
								$("#passport_msg").html("<font color='green'>手机号可用</font>");
							}
						},
						error:function(){
							alert("请求失败！");
						}
					});
				}
			});
	//给注册表单注册submit事件
	$("form").submit(function(){
		return register();
	});
});
function register(){
	var passport=$("form input[name=passport]").val();
	var password=$("form input[name=password]").val();
	
	var flag=formObj.checkForm();
	if(flag){
		$.ajax({
			url:"/user/save",
			type:"post",
			data:{
				  "userPhone":passport,
				  "userPassword":password,
				 
				 },
			dataType:"json",
			success:function(result){
				if(result.status==200){
					alert("注册成功,转向登录页面")
					window.location.href="./login.html";
				}else{
					alert("fail");
				}
			},
			error:function(){
				alert("请求失败！");
			}
		});
	}
	
	return false;
}
var formObj = {
	checkForm : function() {
		var flag = true;
		// 非空验证
		flag = this.checkNull("passport", "手机号不能为空!");
		flag = this.checkNull("password", "密码不能为空") && flag;
		return flag;
	},
	checkNull : function(name, msg) {
		var value = $("input[name=" + name + "]").val();
		if ($.trim(value) == "") {
			this.setMsg(name, msg);
			return false;
		}
		return true;
	},
	setMsg : function(name, msg) {
		$("#" + name + "_msg").text(msg);
	}
};

		</script>      
</head>
<body>

<!-------------------登录------------------->
<div id="log_register">
	
	<div class="lr_box">
		
		<div class="tag">
			<ul>
				<li><a href="login.html">登录</a></li>
				<li><a class="cur" href="register.html">注册</a></li>
				<div class="clear"></div>
			</ul>
		</div>
	<form>
		<table class="table_list">
			<tbody>
				<tr>
					<td><input class="text" name="passport" type="text" placeholder="手机号"></td>
					<td><span style="color: red" id="passport_msg"></span></td>
				</tr>
				<tr>
					<td><input class="text" type="password" name="password" placeholder="您的密码"></td>
					<td><span style="color: red" id="password_msg"></span></td>
				</tr>
				
				<tr>
					<td><input class="submit" type="submit" value="注册"></td>
				</tr>
			</tbody>
		</table>
		</form>
	</div>

</div>

</body>
</html>